//
//  NSObject+XQ.m
//  iLovewCooking
//
//  Created by apple on 2018/8/10.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "NSObject+XQ.h"

@implementation NSObject (XQ)
- (BOOL)isEmpty {
    BOOL isEmpty = YES;
    if ([self isKindOfClass:[NSNull class]]) {
        return YES;
    }
    if(self && self != nil) {
        if([self isKindOfClass:[NSString class]]){
            if (self == nil || self == NULL) {
                return YES;
            }
            if(![@"" isEqualToString:[(NSString *)self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]){
                isEmpty = NO;
            }
        }else if([self isKindOfClass:[NSArray class]]){
            if([(NSArray *)self count] > 0){
                isEmpty = NO;
            }
        }else if([self isKindOfClass:[NSDictionary class]]){
            if([[(NSDictionary *)self allKeys] count] > 0){
                isEmpty = NO;
            }
        }else {
            isEmpty = NO;
        }
    }
    return isEmpty;
}
+ (BOOL)isObjectEmpty:(id)object{
    BOOL isEmpty = YES;
    if ([self isKindOfClass:[NSNull class]] || object == nil) {
        return YES;
    }
    if ([object isEqual:[NSNull null]]){
        return YES;
    }
    if(object && object!=nil){
        if([object isKindOfClass:[NSString class]]){
            if(![@"" isEqualToString:[object stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]){
                isEmpty = NO;
            }
        }else if([object isKindOfClass:[NSArray class]]){
            if([object count]>0){
                isEmpty = NO;
            }
        }else if([object isKindOfClass:[NSDictionary class]]){
            if([[object allKeys] count]>0){
                isEmpty = NO;
            }
        }else{
            isEmpty = NO;
        }
    }
    return isEmpty;
}
@end
